import logging
# --------logging.basicConfig-------------#
'''
logging.basicConfig(
    level='DEBUG',
    filename='rizhi.log',
    filemode='w',
    format="%(asctime)s %(filename)s %(funcName)s [%(lineno)d] %(message)s "
)
# %(levelno)s：打印日志级别的数值
# %(levelname)s：打印日志级别的名称
# %(pathname)s：打印当前执行程序的路径，其实就是sys.argv[0]
# %(filename)s：打印当前执行程序名
# %(funcName)s：打印日志的当前函数
# %(lineno)d：打印日志的当前行号
# %(asctime)s：打印日志的时间
# %(thread)d：打印线程ID
# %(threadName)s：打印线程名称
# %(process)d：打印进程ID
# %(message)s：打印日志信息

logging.debug('debug message')
logging.info('info message')
logging.warning('waring message')
logging.error('error message')
logging.critical('critical message')
'''
# --------logging.logger-------------#
'''
def logfunc():
    logger =logging.getLogger()

    fh=logging.FileHandler('log.log')
    ch=logging.StreamHandler()
    fm =logging.Formatter("%(asctime)s %(filename)s %(funcName)s [%(lineno)d]\
 -%(levelno)s--%(levelname)s- %(message)s ")
    fh.setFormatter(fm)
    ch.setFormatter(fm)

    logger.addHandler(fh)
    logger.addHandler(ch)
    logger.setLevel('DEBUG')

    return logger
# ________________________________________________________
logger =logfunc()
logger.debug('debug message')
logger.info('info message')
logger.warning('waring message')
logger.error('error message')
logger.critical('critical message')
'''

# def logfunction():
from logging.handlers import RotatingFileHandler
logger1 =logging.getLogger("Mylogger")
logger1.setLevel('INFO')
logger2=logging.getLogger('Mylogger.son')
rHandler=RotatingFileHandler("./logreport/log2.log",maxBytes=2*1024,backupCount=3)
fm = logging.Formatter('%(asctime)s %(filename)s %(funcName)s [%(lineno)d]\
-%(levelno)s--%(levelname)s- %(message)s ')
fh=logging.FileHandler('log.log')
ch=logging.StreamHandler()
fh.setFormatter(fm)
ch.setFormatter(fm)

logger1.addHandler(rHandler)
logger1.addHandler(fh)
logger1.addHandler(ch)

# logger2.addHandler(fh)
# logger2.addHandler(ch)
# logger2.setLevel('ERROR')

# _________________________
logger1 =logger1
logger1.debug('logger1 debug message')
logger1.info('logger1 info message')
logger1.warning('logger1 waring message')
logger1.error('logger1 error message')
logger1.critical('logger1 critical message')
#
# logger2 =logger2
# logger2.debug('logger2 debug message')
# logger2.info('logger2 info message')
# logger2.warning('logger2 waring message')
# logger2.error('logger2 error message')
# logger2.critical('logger2 critical message')

